package com.nbicc.spring;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: lilingyan
 * @Date 2018/11/27 10:02
 */
public class CurrentRequestUtils {

    public static HttpServletRequest getRequest(){
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        return request;
    }

    /**
     * 获取远端ip
     * @return
     */
    public static String getRemoteAddr(){
        return getRequest().getRemoteAddr();
    }

}
